/*
 * IfInstructionDescription.java
 * 
 * last update: 01.02.2010 by Florea Mihai
 * 
 * author:	Power(power@kermit.cs.pub.ro)
 * 			Florea Mihai(florea.mihai@gmail.com)
 * 
 * Obs: Am adaugat @SuppressWarnings("serial").
 */


package engine;

@SuppressWarnings("serial")
class IfInstructionDescription extends InstructionDescription{
	ExpressionDescription ed;
	InstructionDescription idTrue, idFalse;

	IfInstructionDescription(int db, int line, NameSpaceDescription nsd, ExpressionDescription ed,
			InstructionDescription idTrue, InstructionDescription idFalse){
		super(db, line, nsd);
		this.ed = ed;  this.idTrue = idTrue;  this.idFalse = idFalse;
	}

	DefaultInstruction instantiate(NameSpace ns)throws ParseException{

		Expression edInstance;
		try{
			edInstance = ed.instantiate(ns);
		}catch(ParseException ex){
			xConsole.dumpStack(ex);
			throw new ParseException(super.toString() + " error:" + ex);
		}

		return new IfInstruction(ns, delayBefore, this, edInstance, idTrue.instantiate(ns),
				idFalse == null ? null : idFalse.instantiate(ns), next == null ? null : next.instantiate(ns));
	}

	public String toString(){
		return super.toString() + "if( " + ed + ")";
	}
}










